package com.doit.day03

/**
 * map
 * flatten
 * flatMap
 * filter
 * max
 * min
 * groupBy
 * reduce
 */
object _12_聚合类的算子2 {
  def main(args: Array[String]): Unit = {
    val list: List[Int] = List(1, 2, 3, 4, 5)

    //reduce
    println(list.reduce((a: Int, b: Int) => a + b))
//    1, 2  -1  -3  -4 -5
    println(list.reduce((a: Int, b: Int) => a - b))

//    4 给了a  5 给了b  -1  3-（-1） = 4  2-4 = -2  1-(-2) = 3
    println(list.reduceRight((a: Int, b: Int) => a - b))


    val str: Any = list.reduce((a: Any, b: Any) => a + "," + b)
    println(str)




  }

}
